// HSS.Logging.ProjectInstaller.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       ProjectInstaller.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;

namespace HSS.Logging
{
	/// <summary>
	/// Logging Service installer
	/// </summary>
	[RunInstaller(true)]
	public partial class ProjectInstaller : Installer
	{
		/// <summary>
		/// Default Constructor
		/// </summary>
		public ProjectInstaller()
		{
			InitializeComponent();

			this.serviceInstaller1.Description = Resources.logServiceDescription;
			this.serviceInstaller1.DisplayName = HSS.Logging.Resources.logServiceDisplayName;
			this.serviceInstaller1.ServiceName = HSS.Logging.Resources.logServiceName;
			this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;

		}

		/// <summary>
		/// Install custom actions
		/// </summary>
		/// <param name="stateSaver"></param>
		public override void Install(IDictionary stateSaver)
		{
			//
			// Actually performs Install actions
			// NOTE: You must call this otherwise the installation state is inconsistent
			// and will cause the overall installation process to fail
			//
			base.Install(stateSaver);
		}
		/// <summary>
		/// Rollback custom actions
		/// </summary>
		/// <param name="savedState"></param>
		public override void Rollback(IDictionary savedState)
		{
			//
			// Actually performs Rollback actions
			// NOTE: You must call this otherwise the installation state is inconsistent
			// and will cause the overall install process to fail
			//
			base.Rollback(savedState);
		}
		/// <summary>
		/// Uninstall custom actions
		/// </summary>
		/// <param name="savedState"></param>
		public override void Uninstall(IDictionary savedState)
		{
			//
			// Actually performs Uninstall actions
			// NOTE: You must call this otherwise the installation state is inconsistent
			// and will cause the overall uninstall process to fail
			//
			base.Uninstall(savedState);
		}

		/// <summary>
		/// Commit the Install process and start the Service.
		/// </summary>
		/// <param name="savedState"></param>
		public override void Commit(IDictionary savedState)
		{
			//
			// Actually performs Commit actions
			// NOTE: You must call this otherwise the installation state is inconsistent
			// and will cause the overall uninstall process to fail
			//			
			base.Commit(savedState);

			try
			{
				HSS.ServiceManager.GetService(this.serviceInstaller1.ServiceName).StartService(TimeSpan.FromSeconds(30));
			}
			catch (Exception ex)
			{
				HSS.Logging.Log.WriteToMachineEventLog(ex.ToString(), MachineEventLogSource.Installer);
			}
		}
	}
}